import $ from 'jQuery';
(function () {
    var _modifyPara =function(rowData){//
        console.log(rowData);
        $('#paraNum').val(rowData.paraCode);
        $('#paraValue').val( rowData.paraValue);
        $('#paraText').val(rowData.paraNote);
        layer.open({
            type: 1,
            title: ['修改参数'],
            area: ['400px', '350px'],
            content:$('#modifyPara'),
            btn: ['确定', '取消'],
            yes: function(index, layero){
                //按钮【按钮一】的回调

                $vue.para.paraId = rowData.paraId;
                $vue.para.paraCode = $('#paraNum').val();
                $vue.para.paraValue = $('#paraValue').val();
                $vue.para.paraNote = $('#paraText').val();
                $('#paraNum').val('');
                $('#paraValue').val('');
                $('#paraText').val('');
                let params = $vue.$data.para;
                layer.closeAll();
                IOT.showOverlay('保存中，请稍等...');
                IOT.getServerData(URI.SYSTEM.SYSTEMPARA.MODIFY , params, function (ret) {
                    IOT.hideOverlay();
                    if (ret && ret.code === 200) {
                        IOT.tips('保存成功！', 'success');
                        M.Table.refresh.all();
                    } else {
                        IOT.tips(ret.msg || '操作失败，请重试！', 'error', 1000, null);
                    }
                });
                return false;
            },
        })
    };
    let $vue = new Vue({
        el: '.main-hook',
        data: {
            boxs: {
                box1: {show: true, hook: '.box1-hook', lock: true, url: '', params: {}},
                box2: {show: false, hook: '.box2-hook', url: '', params: {}},
                box3: {show: false, hook: '.box3-hook', url: '', params: {}},
                box4: {show: false, hook: '.box4-hook', url: '', params: {}}
            },
            para: {
                paraId:'',
                paraCode:'',
                paraValue:'',
                paraNote:''
            }
        },
        created: function () {
            M.Request.getRoleList(true, (roleList, ret) => {
                this.roleList = roleList;
            });
        },
        methods: {
            emitPage: function () {
                M.Page.load(this.boxs);
            },
            // 上一页
            prePage: function () {
                M.Page.prePage(this.boxs);
            },
            searchKey:function(){
                $('.search-hook').trigger('click');
            },
            // 触发刷新页(当前显示的页面)
            refreshPage: function () {
                M.Page.refreshPage(this.boxs);
            },
            // modifyPara: function () {
            //  M.Page.emit(URI.OPERATE.GROUPS.CREATE.PAGE);
            // }
        },
        mounted: function () {
            let thiz = this;
            this.$nextTick(() => {
                let tableHookName = '.systempara-table-hook';
                let $accountBox = $('.groups-hook');
                //初始化时间插件
                // modal.initDate("startdate","enddate");
                var $form = $accountBox.find('.form-hook');
                // 查询
                $form.off('submit').on('submit', function () {
                    $(tableHookName).bootstrapTable('onCustomSearch');
                    return false;
                });
                var $tableHook = $accountBox.find(tableHookName).bootstrapTable({
                    scrollbar: 'groups-table-body',
                    striped: true, // 设置为 true 会有隔行变色效果
                    pagination: true, // true 显示分页
                    paginationDetail: true, // 分页详情
                    sidePagination: 'server', // 服务器端
                    method: 'post',
                    url: URI.SYSTEM.SYSTEMPARA.LIST,
                    debug: false,
                    cache: false,
                    pageNumber: 1,
                    pageSize: 10,
                    pageList: [10, 20, 50, 100],
                    smartDisplay:false,
                    // fixedColumns: true,
                    customButton: '',
                    customQueryParams: function (params) {
                        var formParams = $form.serializeJson();
                        var queryParams = $.extend({}, params, formParams);
                        //console.log(queryParams);
                        return queryParams;
                    },
                    onLoadSuccess: function (data) {
                        //console.log(JSON.stringify(data));
                    },
                    onLoadError: function (status, xhr) {
                    },
                    onCheckAll: function (rows) {

                    },
                    columns: [
                       
                        /*{
                            field: 'no', title: '序号', align: 'center', width: 50,tips:true,
                            formatter: function (value, row, index) {
                                var pageSize =  $accountBox.find(tableHookName).bootstrapTable('getOptions').pageSize;     //通过table的#id 得到每页多少条
                                var pageNumber = $accountBox.find(tableHookName).bootstrapTable('getOptions').pageNumber; //通过table的#id 得到当前第几页
                                return pageSize * (pageNumber - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
                            }
                        },*/
                        // {
                        //     field: '', radio: true, align: 'center', fixedLeft: true, width: 60,
                        //     events: {
                        //         'change .radio-hook': function (e, value, row, index) {
                        //             console.log('单选框: ' + value);
                        //         }
                        //     }
                        // },
                        {
                            field: 'paraCode', title: '参数代码', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'paraState', title: '参数状态', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'paraValue', title: '参数值', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'paraNote', title: '参数说明', align: 'center', fixedLeft: true,tips:true
                        },
                        {
                            field: 'operate', title: '操作', align: 'center', fixedLeft: true, width: 180,
                            events: {
                                'click .modify-account': function (e, value, rowData, index) {
                                    _modifyPara(rowData);
                                    // return false;
                                    // IOT.setSessionStore(URI.SYSTEM.SYSTEMPARA.PAGE, JSON.stringify(rowData));
                                    // return false;
                                }
                            },
                            formatter: function (value, row, index) {
                                let html = [];
                                if (M.Authority.checkAuthority('account-modify')) {
                                    html.push('<a class="modify-account operate">修改</a>');
                                }
                                return html.join('');
                            }
                        }
                    ]
                });
                //权限——查看
                if (!M.Authority.checkAuthority('account-detail')&&!M.Authority.checkAuthority('account-modify')) {
                    $(tableHookName).bootstrapTable('hideColumn', 'operate');//隐藏列
                }
            });
        }
    });
})();